Hey there.
We're going to be wrapping up the first section of our story in this lecture, the last things we need
to do is have our Squidward walk to the basement and open the doors, and then we'll force the players
to wait a little bit, and then afterwards we'll play a sound to make it sound like Squidward is screaming
from the basement, which means the players will then be tasked at locating Squidward and restoring
power in the basement.
So let's get started.
So after all of our tasks are complete and the power is turned off and the entire building turns dark,
what we're going to want to do next is our game comms bindable, and we want to fire and give the action
in our game comms enum for the server, and we want to give the action inside of the normal Squidward
service to move Squidward.
So he's going to be walking, and the positions we need to give to the service is going to be inside
of the workspace dot filtering folder, and there's a folder in there called Pathfinding Parts, and
there's a folder in there containing all the parts that are normal.
Squidward needs to walk to.
So inside of the main story here, as you can see, here's one of the invisible parts he's going to
be unanchored.
He's going to walk first to this point, we're going to open this door, and then he's going to walk
to the second point.
And here after we open this door, and then he's going to walk finally to this last part right here.
So we'll just walk down the stairs and then we're going to remove him from the game because we don't
need him anymore.
So in order to do this, that means we're going to have to script the functionality for moving our Squidward
so we can go inside of server script service and open up our normal Squidward service.
And we already have our function in here to move our Squidward to a particular position.
So that means the first thing in this function that we would have to do is un anchor our Squidward.
So let's go ahead and create a reference to his route part.
So after we get his humanoid, we can also get the route part inside of regular Squidward dot humanoid
route part.
Another important thing that we have to do is on our humanoid.
We want to set a state to be disabled, so we're going to use the enum dot humanoid state type, and
we're going to refer to the falling down state type.
And we want to disable the state type from ever occurring on our Squidward.
And this is because when our Squidward gets un anchored or is humanoid route part gets un anchored,
he's going to be put into the falling down state, and that means he's going to fall over, which doesn't
look very nice.
So we make sure to disable that state on our humanoid so it never occurs in the first place.
We're also going to want to make a reference to the door event to be able to open doors using the door
service.
So that's in service storage dot events dot Bindesboll's dot door.
And then I'm also going to create a constant down here to keep track of the hip height for our humanoid,
just in case it gets reset.
And the hip height for our humanoid is 2.4 studs.
So now inside of our move Squidward to Positions function, the first thing we need to do is get our
root part and anchor it.
So we'll make anchored false, and then we're going to set the root parts network ownership to the server.
Or basically we don't pass anything to this function.
That way the server has control over all the functionality for our Squidward, and an exploiter isn't
able to move around his position if they have network ownership over his root part.
But since we set it to the server, we fix that problem, and then we're going to get all the positions
passed to the args table, which is the key positions, and we get all of those children, which is
every single one of those parts.
Another important thing we got to make sure real quick after we un anchor them, is we want to make
sure that the humanoid hip height is equal to the hip height we defined in that constant.
And then we can loop through every single position part.
So we'll get the index and the position inside of positions.
And what we're going to do is we're going to use the move two function inside of our humanoid.
Now that he's un anchored.
And it's going to force him to walk to a particular position, and the position we want him to walk
to is going to be our position.
Part dot position.
So this is going to sequentially move through each of those three positions.
So we'll wait for our humanoid to get to that position.
So there's an event called Move to Finished.
And we're going to wait for this to fire.
That way it signifies whether or not he has reached this position yet.
And then once that's done, we want to check the current index that we're at in this position table.
If he reaches this first position, we're going to want to open this door as well as this door.
And then when he reaches the second position, we're going to want to close this door.
So what we could do is we could check if I is equal to one.
If it is, then we're going to use our door event and fire to open a door.
And that door is going to be inside of the workspace.
So the door model is equal to workspace dot krusty Krab, dot doors, dot kitchen door, and the proximity
prompt we need to refer to will be the first prompt inside of this door.
So workspace dot krusty krab dot doors dot kitchen door dot prompt part.
We'll get attachment number one and refer to the proximity prompt that is inside of there.
So that means the door when this open is going to swing in this direction.
And then after that, we don't want the players to be able to close this door on our Squidward.
So we're going to go down here and we're going to lock this door as well.
And we don't need to pass the proximity prompt to it because we're just locking the door.
And then we want to make sure to do the same thing for the basement door, but we have to unlock the
basement door before we open it.
So what we're going to do is I'm going to copy this, paste this here.
This one right here can go right here.
We want to unlock a door.
And that door model is going to be the basement door.
And then we want to go ahead and open the basement door.
And we'll refer to the correct proximity prompt.
So inside of the basement door we get the prompt part attachment one and get the proximity prompt in
there.
And after we open it we're going to relock the door.
So again the players are unable to close the door in his face.
So we're going to actually just copy this up here.
And this time we're going to lock the basement door.
And that should be good to go here.
And then the next thing we can check is if the index reaches two, which means he is now inside of this
room right here.
If he's inside of here, that means we're going to have to shut this door.
So that means we're going to have to unlock it again and then relock it.
And if you actually don't want to do that, we could just get rid of this right here or copy it.
And then we can just have it lock it afterwards because we want to open it and then we want to close
it.
So copy this.
We want to get rid of this because we don't care about the proximity prompt.
And we want to go ahead and close the basement door.
So close door.
And then when we close it then we go ahead and lock the door.
And then after this completes, once Squidward is inside of the basement, we can go ahead and unlock
the kitchen door again because it doesn't need to be locked anymore.
So we're just going to copy this here.
So once we're done looping, we're going to go ahead and unlock the door.
And since Squidward is already going to be inside of that room and that door is going to be shut, we're
just going to go ahead and destroy our regular Squidward because we do not need him anymore.
Okay, so now that our Squidward has walked and he's inside of the basement, what we need to do now
is give a new objective to the player.
So Updateui event we're going to fire to all the clients GUI actions enum.
We're going to add an objective.
And that means we're going to have to add a new objective to our objectives table.
So if we go ahead and scroll up we want to add two new objectives.
One of these objectives is to go ahead and wait for Squidward.
And inside of here we can set the text equal to wait for Squidward to restore the power.
And then the other objective we'll need is that once Squidward screams for his life and we don't know
where he's at, we're going to get a new objective of needing to go to the basement, so we'll call
it Go to basement.
And the text for this one's going to be go to the basement and find Squidward.
And since we're basically going to automatically make this objective fail because Squidward isn't going
to restore the power and come back, we don't need to add a fulfilled boolean in here, but we will
keep track of the fulfilled boolean inside of this one, which will be false as default for now, and
then we can go back down.
And the objective name we need to add is going to be wait for Squidward.
And the text is inside of game sections.
Dot objectives dot wait for Squidward and we get the text inside of there.
And after we do that, we're just going to wait for a random amount of time so we can do task dot wait
and use RNG next number, and we'll wait anywhere between 12 and 22 seconds just to build up a little
bit of suspense.
And then after that time is up, we're going to play the scream sound for Squidward.
So using the Game Comms event, we're going to fire to all of the clients using the Game Comms enum
client two client play sound, and the sound we wish to play is inside of the sound service.
Dot SFX and there's a Squidward scream sound inside of there, so I'll show you what it sounds like.
Here we go in SFX Here's Squidward scream.
We're going to play this!
It's 15 seconds long about.
So that means after we play it, we're going to want to wait for 15 seconds just to ensure that the
sound has ended.
But we do want to play this sound at a particular point, which is going to be inside of the basement.
So we're going to set play at point equal to true.
And the position that we want to set it to is inside of server storage.
And inside of the other stuff folder there's a folder called Audio Positions.
And inside of there we have a single part for the Squidward scream.
So this denotes the position inside of our basement.
We want the sound to emanate from, so we give that position to the client.
The client creates the part of the position and plays that sound from that point.
And then we can wait for 15 seconds, and after we wait for 15 seconds, we're going to use the Updateui
event and fire to all of the clients that they have failed.
The objective, which was to wait for Squidward.
So G actions enum dot objective failed.
And our failed objective is going to be equal to the wait for Squidward.
And then after that, we're going to use the update UI event again, and we're going to fire to all
the clients to add the new objective, which is to go to the basement.
So GUI actions enum dot add objective and that objective name is go to basement and the text is going
to be equal to game sections.
Dot objectives dot go to basement dot text.
And then once we do that we're going to use our door event.
And we need to go ahead and unlock the basement door again so the players can actually open it and go
into the basement.
And we're also going to need to make the can collide on this invisible part in front of our door.
We need to disable it because this part stops any players from trying to go into the basement when this
door is open and Squidward is walking through it.
Once we need to go look for Squidward, we're going to have to set the Can Collide property to false.
So door event.
We're going to fire to unlock a door, and the door we need to lock, so we'll reference the door model
is in the workspace.
Dot Krusty Krab doors dot basement door, and then we're going to refer to the workspace inside of the
filtering folder.
We're going to get the basement blocking wall and we're going to set can collide equal to false.
And that allows our players to go into the basement.
And guess what.
Our start section one function is complete.
That means in the next section we'll have another function.
We could call it start section two that will get executed for all of the basement functionality.
But for right now, let's go ahead and test what we've got completed inside of Start section one.
So we are writing to the restaurant, and then we're going to get dropped off and we'll head inside.
And once we go inside, we're going to have to listen to Squidward talk for a little bit, and then
we should get our task set up after he's done speaking.
So now we can go ahead and start working on all of our tasks.
We'll go ahead and clean the floor.
And of course, you can change the number of tasks inside of the script.
Or you can even script a system where, depending on the number of players that are going to be inside
of the game, you could change the tasks to match the amount of players that you have.
So if there's only one player, you don't want to overwhelm them with too many tasks.
But if there's a lot of players, then you might want to give them a lot of tasks.
And the last thing we need to do is grab our food here, grab our food, and then we can go ahead and
head into the kitchen, and we'll go ahead and refill the fridge.
And just to test that, this door will open, I'm actually going to shut it on Squidward and let's see
if he can go ahead and walk inside of there.
So he's going to go check the breaker in the basement.
We've got our glow stick, and let's go ahead and see how he walks to these different points.
We haven't added a walking animation to him.
I don't think it's very necessary, but you can go ahead and add one if you'd like.
And it looks like we did get an error in the console.
So let's go ahead and check out what that is real quick.
So inside of line 61, in our normal Squidward service, we're attempting to index nil with Get Children.
So that is our positions that we get passed from.
Move Squidward to positions.
So that means let's go ahead and take a look inside of the game sections when we go and fire our games
combined.
Able to move Squidward.
Ah!
And the reason being is because we set this to be position and not positions.
So it's very important that you have the strings matching inside of your scripts, so make sure that's
positions and not position.
Okay.
We can go ahead and try this out again okay.
Now we have our glow stick.
And let's go ahead and see if Squidward actually walks to the points this time.
So after he's done talking here, let's see if he opens this door.
And we'll also check to see if he actually opens the basement door.
So I'll stand right in here to go see if he moves.
Okay, there we go.
He opens that both doors open and as you can see, we were unable to enter into the basement because
that invisible wall walked us from entering.
And as you can see, the doors locked.
We were not able to go in, but this door did get unlocked.
So we're able to open and close it again.
Now it does look like we did get another error.
Unable to assign property position vector three expected, but we got nil.
So it looks like we probably had another typo inside of our function that we're going to go ahead and
have to fix.
So looks like we actually got a total of two errors.
One is we were unable to assign property position vector, three expect to got nil and an argument one
missing or nil.
So let's go ahead and tackle this one first.
Whatever we pass from the server we pass them nil for some reason.
So if we go ahead and go back to the game sections and we look at where we want them to play a sound.
Ah, the reason is because we're actually passing the part instance itself instead of the actual vector
three.
So we need to get the position of this part and pass that instead.
And then for this other function we're getting an error of argument one missing or nil to the fail objective
function.
So if we go into starter player starter player scripts and we go and open up our main GUI handler and
go down to line 66, we can see what exactly is nil in this case failed objective.
When we go to our objective frame and get into our objective list and find which objective was passed
to this function.
Apparently, possibly this string right here could be nil.
So what we're going to do is we're going to double check real quick when we tell them to fail an objective.
There we go.
There's our problem.
We put failed objective, but we forgot to include the extra string of name.
So the total string is failed objective name and not failed objective.
Again, very important to match your strings.
So we fix that problem and we should have fixed our audio problem.
So let's go ahead and test it out one last time.
Okay.
Squidward goes into the basement and he's gone.
And now we're going to wait and see if any errors pop up again.
But hopefully we shouldn't get any errors this time.
Okay, there we go.
We can hear Squidward screaming in the distance.
Sounds like it's coming from under the ground in the basement.
So there we go.
We get a new objective, go to the basement and find Squidward.
So that means we should be able to open this door.
Perfect.
And we should be able to walk through.
Perfect.
Now, this is the time where we would walk down into the stairs and we would touch this basement part,
which would start the next section of our game.
So when a player touches this invisible part that's right here, we're going to teleport all the players
here.
This flashlight is going to be on the floor.
And we're going to tell the players to collect this flashlight.
And then this is when the horror game starts.
They're going to be tasked with figuring out how to restore the power.
And then they're going to have to try and escape the basement while they're being hunted down.
Now to get them trapped in the basement.
What we're going to do is when that part gets touched, we're going to move all the players down there.
We're going to have their camera move to that part that's inside of here, looking down at the stairs,
and we're going to put our bad Squidward guy right here, and he's going to push this crate down on
the stairs.
It's going to break the stairs.
And then we're just going to block them from being able to exit the basement.
And then from this point, it's up to them to explore the basement and try to find the key that will
go ahead and unlock our breaker room, which is over here.
So when they try to interact with this, it tells them the door requires the key breaker room key.
So they're going to be like, huh, we have to find a key in this place.
Otherwise, congratulations, we have wrapped up our first section of the story and the next section
of the course.
We're going to be working on the second part of our story, which includes creating the AI Squidward
monster that's going to be hunting down our players.
See you there.